package com.fdd.service.impl;

import com.fdd.dao.BookDao;
import com.fdd.dao.UserDao;
import com.fdd.service.BookService;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

public class BookServiceImpl implements BookService, InitializingBean, DisposableBean {
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    // 当自动注入byName时，成员变量的名字要和bean id保持一致，所以我们这里要命名为bookDao1，因为在xml中我们是这个id。
    // 注意setter方法的形参不受名字限制。
    public void setBookDao1(BookDao abc) {
        this.bookDao1 = abc;
    }

    private UserDao userDao;
    private BookDao bookDao1;

    public BookServiceImpl() {
        System.out.println("BookServiceImpl::BookServiceImpl()");
    }

    @Override
    public void save() {
        System.out.println("BookServiceImpl::save()");
        bookDao1.save();
        userDao.save();
    }

    @Override
    public void destroy() {
        System.out.println("Destroy ...");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("init ...");
    }
}
